import tab from '@/store/tab';
import Mock from 'mockjs'

// 模拟数据
let tableData = [
    {
        user_id:'2021211111',
        user_name:'a10000',
        entry_year:'2021',
        college_name:'未来学院',
        major:'计算机科学与技术',
        grade:'大三',
        points:3
    },
    {
        user_id:'2021211112',
        user_name:'a10001',
        entry_year:'2019',
        college_name:'国际学院',
        major:'软件工程',
        grade:'研二',
        points:0
    },
    {
        user_id:'2021211113',
        user_name:'a10003',
        entry_year:'2023',
        college_name:'计算机学院（国家示范性软件学院）',
        major:'数据科学与人工智能',
        grade:'大一',
        points:8
    },
    {
        user_id:'2021211114',
        user_name:'a10004',
        entry_year:'2021',
        college_name:'人工智能学院',
        major:'人工智能与机器人',
        grade:'大二',
        points:0
    },
    {
        user_id:'2021211115',
        user_name:'a10005',
        entry_year:'2015',
        college_name:'电子工程学院',
        major:'信息安全',
        grade:'博士生',
        points:22
    },
    {
        user_id:'2021211116',
        user_name:'a10006',
        entry_year:'2023',
        college_name:'经济管理学院',
        major:'市场营销',
        grade:'大一',
        points:5
    },
    {
        user_id:'2021211117',
        user_name:'a10007',
        entry_year:'2021',
        college_name:'数字媒体与设计艺术学院',
        major:'数字媒体设计',
        grade:'大三',
        points:11
    },
    {
        user_id:'2021211118',
        user_name:'a10008',
        entry_year:'2022',
        college_name:'信息与通信工程学院',
        major:'通信工程',
        grade:'大三',
        points:5
    },
    {
      user_id:'2021211119',
      user_name:'a10009',
      entry_year:'2020',
      college_name:'计算机科学与技术学院',
      major:'计算机科学与技术',
      grade:'大三',
      points:8
  },
  {
      user_id:'2021211120',
      user_name:'a10010',
      entry_year:'2019',
      college_name:'机械与动力工程学院',
      major:'机械工程',
      grade:'大四',
      points:15
  },
  {
      user_id:'2021211121',
      user_name:'a10011',
      entry_year:'2020',
      college_name:'化学化工与环境学院',
      major:'化学工程与工艺',
      grade:'大三',
      points:9
  },
  {
      user_id:'2021211122',
      user_name:'a10012',
      entry_year:'2021',
      college_name:'法学院',
      major:'法学',
      grade:'大二',
      points:3
  },
  {
      user_id:'2021211123',
      user_name:'a10013',
      entry_year:'2020',
      college_name:'外国语学院',
      major:'英语',
      grade:'大三',
      points:7
  },
  {
      user_id:'2021211124',
      user_name:'a10014',
      entry_year:'2019',
      college_name:'土木工程与建筑学院',
      major:'土木工程',
      grade:'大四',
      points:16
  },
  {
      user_id:'2021211125',
      user_name:'a10015',
      entry_year:'2021',
      college_name:'艺术设计与创意产业学院',
      major:'视觉传达设计',
      grade:'大二',
      points:4
  },
  {
      user_id:'2021211126',
      user_name:'a10016',
      entry_year:'2019',
      college_name:'电子与信息工程学院',
      major:'电子信息工程',
      grade:'大四',
      points:18
  },
  {
      user_id:'2021211127',
      user_name:'a10017',
      entry_year:'2020',
      college_name:'物理与光电工程学院',
      major:'光电信息科学与工程',
      grade:'大三',
      points:10
  },
  {
      user_id:'2021211128',
      user_name:'a10018',
      entry_year:'2021',
      college_name:'数学与统计学院',
      major:'数学与应用数学',
      grade:'大二',
      points:6
  }
    ];
  
  // 获取所有数据
  export const getAllData = () => {
    return tableData;
  };
  
  // 添加数据
  export const addData = (newData) => {
    tableData.push(newData)
    console.log(newData)
    console.log(tableData);
  };
  
  // 根据用户名删除数据
  export const deleteData = (dataToDelete) => {
    console.log("tableData0",tableData)
    console.log("dataToDelete0",dataToDelete)
    tableData = tableData.filter(data => {
        // console.log("dataToDelete",dataToDelete)
        // console.log(data)
        return (
            //不能使用data !== dataToDelete,他们是不同引用
            data.user_name !== dataToDelete.user_name ||
            data.entry_year !== dataToDelete.entry_year ||
            data.college_name !== dataToDelete.college_name ||
            data.major !== dataToDelete.major ||
            data.grade !== dataToDelete.grade ||
            data.points !== dataToDelete.points
            // 可以根据需要继续添加其他属性的比较
          );
        }
    );
    console.log("tableData1",tableData)
  };
  
  // 根据用户名修改数据
  export const updateData = (updateData) => {
    tableData = tableData.map((data) => {
      if (data.user_id === updateData.user_id) {
        return { ...data, ...updateData };
      }
      return data;
    });
  };
  
  // 导出整个模块
  export default {
    getAllData,
    addData,
    deleteData,
    updateData
  };
  